<?php
class Menu extends MY_Controller{

	function __construct()
	{
		parent::__construct();
	}

	function index()
	{
		$data['category'] = category::find('all'); 
		$data['title'] = $this->title('La Carte');
		$this->load->view($this->theme.'/header',$data);
		$this->load->view($this->theme.'/menu');
		$this->load->view($this->theme.'/footer');
	}

	function getContent()
	{
		$data = array();
		if($_POST){
			$content = product::find('all',array('conditions'=>array('category_id'=>$_POST['cat_id'])));
			if($content){
				foreach ($content as $c){
					$data[] = array('id'=>$c->id,'product_name'=>$c->product_name,'category_id'=>$c->category_id,'subtitle'=>$c->subtitle,'description'=>$c->description,'price'=>$c->price,'num'=>$c->num);				
				}
				echo json_encode($data);				
			}else{
				echo json_encode(false);
			}
		}else{
			redirect('menu');
		}
		
		
	}
	

	function add()
	{
		if($_POST)
		{
			$dataP = array('id'=>'','product_name'=>$_POST['product_name'],'category_id'=>$_POST['category_id'],'subtitle'=>$_POST['subtitle'],'description'=>$_POST['description'],'price'=>$_POST['price'],'num'=>$_POST['num']);
			$newItem = product::create($dataP);
			if($newItem){
				redirect('menu/add');
			}
		}
		$data['category'] = category::find('all');
		$data['title']= $this->title('add');
		$this->load->view($this->theme.'/header',$data);
		$this->load->view($this->theme.'/add');
	}
	
	
}